


from selenium.webdriver.common.by import By

from utils import UtilsDriver
from base.base_page import BasePage,BaseHandle

# 对象库层，用于定位元素
class LoginPage(BasePage):
    def __init__(self):
        # 初始化Driver对象
        # self.driver = UtilsDriver.get_driver()
        super().__init__()
        self.login_username = By.XPATH,'/html/body/div[4]/div/div[2]/div[2]/div/div/div[1]/form/div[1]/input'
        self.login_password = By.XPATH,'/html/body/div[4]/div/div[2]/div[2]/div/div/div[1]/form/div[2]/div/input'
        self.login_btn = By.XPATH,'/html/body/div[4]/div/div[2]/div[2]/div/div/div[1]/form/div[3]/button'

    def get_login_username(self):
        # 定位用户名输入框，并返回
        return self.get_element(self.login_username)

    def get_login_password(self):
        return self.get_element(self.login_password)

    def get_login_btn(self):
        return self.get_element(self.login_btn)

# 操作层
class LoginHandle(BaseHandle):
    def __init__(self):
        # 实例化对象库对象
        self.login_page = LoginPage()

    def input_login_username(self,username):
        # 输入用户名
        # self.login_page.get_login_username().clear()
        # self.login_page.get_login_username().send_keys(username)
        self.input_text(self.login_page.get_login_username(),username)

    def input_login_password(self,password):
        self.input_text(self.login_page.get_login_password(),password)

    def click_login_btn(self):
        self.login_page.get_login_btn().click()


#业务层
class LoginProxy:
    def __init__(self):
        # 实例化操作层对象
        self.index_handle = LoginHandle()

    def go_login(self):
        # 登录跳转首页
        self.index_handle.input_login_username('admin')
        self.index_handle.input_login_password('123456')
        self.index_handle.click_login_btn()



